<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="resources/css/main.css" />

<script type="text/javascript" src="resources/js/jquery-1.7.1.min.js"></script>

<style type="text/css">
	.line{
		margin: 0;
		padding: 5px; 
	}

</style>

<title>$.getJSON()</title>

<script type="text/javascript">
	$(function(){
		$('input:button').click(
			function(){
				$.getJSON(
					'json',
					$('form').serialize(),
					function(data){
						$("div").empty()
						$.each(data,
							function(index, person){
								$("div")
									.append( 
										'<p> Name: ' 
										+ person.name 
										+ ' - Age: ' 
										+  person.age 
										+ '</p>'
									)								
							}							
						);

						$('p', $('div')).each(
								function(index){
								 	$(this).addClass('line')
								 	if(index % 2 == 0){
						            	 $(this).css('background-color', '#E8E8E8');
									}									 
								}								
							);	
					}
					
				);	
			}
		);
	});	
</script>


</head>

<body>
<h4>$.getJSON()</h4>
<hr />
<form>
	<p>
		<label for="name">Name:
			<input type="text"  name="name" />
		</label>
	</p>
	<p>
		<label for="age">Age:
			<input type="text" name="age"/>
		</label>
	</p>
	<input type="button" value="submit"/>
	<br/><br/>
	<div>
	</div>	
</form>

</body>
</html>